package com.androidcourse.shounews.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.androidcourse.shounews.Entity.MyNews;
import com.androidcourse.shounews.R;

import java.util.List;

public class MyNewsAdapter extends RecyclerView.Adapter<MyNewsAdapter.MenuViewHolder> {
    private List<MyNews> list;

    private OnItemClickListener listener;
    public MyNewsAdapter(List<MyNews> list,OnItemClickListener listener) {
        this.list = list;
        this.listener=listener;
    }
    public interface OnItemClickListener{
        public void OnMyNewsItemClick(int position);
        public void OnMyNewsItemLongClick(int position);
    }
    public class MenuViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
        private TextView name;
        public MenuViewHolder(@NonNull View itemView) {
            super(itemView);
            name=itemView.findViewById(R.id.menu_recycle_view_item_name);
            itemView.setOnClickListener(this);
            itemView.setOnLongClickListener(this);
        }
        @Override
        public void onClick(View v) {
            listener.OnMyNewsItemClick(getAdapterPosition());
        }

        @Override
        public boolean onLongClick(View v) {
            listener.OnMyNewsItemLongClick(getAdapterPosition());
            return true;
        }
    }
    @NonNull
    @Override
    public MenuViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.recycle_view_my_news,parent,false);
        return new MenuViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MenuViewHolder holder, int position) {
          MyNews myNews =list.get(position);
          holder.name.setText(myNews.getName());
    }
    @Override
    public int getItemCount() {
        return list.size();
    }
}
